package net.oschina.app.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.BlogBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by elf on 2017/1/15.
 */

public class MeBlogRvAdapter extends BaseAdapter {


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(CommonUtils.getContext()).inflate(R.layout.item_blog, parent, false);
        MeBlogHolder meBlogHolder = new MeBlogHolder(itemView);
        //将创建的View注册点击事件
        return meBlogHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BlogBean blogBean = (BlogBean) mDatas.get(position);
        MeBlogHolder meBlogHolder = (MeBlogHolder) holder;
        meBlogHolder.mTvTitleBlog.setText(blogBean.getTitle());
        meBlogHolder.mTvAuthorBlog.setText(blogBean.getAuthorname());
        meBlogHolder.mTvPubDate.setText(blogBean.getPubDate());
        meBlogHolder.mTvComment_Count.setText(blogBean.getCommentCount() + "");
    }


    static class MeBlogHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title_blog)
        TextView mTvTitleBlog;
        @BindView(R.id.tv_author_blog)
        TextView mTvAuthorBlog;
        @BindView(R.id.tv_pubDate)
        TextView mTvPubDate;
        @BindView(R.id.tv_comment_count)
        TextView mTvComment_Count;


        MeBlogHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
